#include "irset.h"

uchar modify_ir=0;
uchar ircode=0;

void ir_setting()
{	
	ircode=irdecode();
	
	if(ircode==2)
	{
		ircode=0;
		flag=1;
		clkbit++; 				
		if(clkbit==1)
		{
		 Locate_xy(7,0);			 //sec
		 sentbyte(0x0d,0);
		 delay(20);						 //wait 1602
		}
		if(clkbit==2)
		{
		 Locate_xy(4,0);			 //min
		 sentbyte(0x0d,0);
		 delay(20);						 //wait 1602
		}
		if(clkbit==3)
		{
		 Locate_xy(1,0);			 //hou
		 sentbyte(0x0d,0);
		 delay(20);						 //wait 1602
		}
		if(clkbit==4)
		{
		 Locate_xy(9,1);			 //day
		 sentbyte(0x0d,0);
		 delay(20);	
		}
		if(clkbit==5)
		{
		 Locate_xy(6,1);			 //mon
		 sentbyte(0x0d,0);
		 delay(20);						 //wait 1602
		}
		if(clkbit==6)
		{
		 Locate_xy(3,1);			 //year
		 sentbyte(0x0d,0);
		 delay(20);						 //wait 1602
		}
		if(clkbit==7)
		{
		 Locate_xy(15,1);			 //week
		 sentbyte(0x0d,0);
		 delay(20);						 //wait 1602
		}
		if(clkbit==8)
		{	
			flag=0;
			clkbit=0;
			if(modify_ir==1)
			{
				modify_ir=0;
				write_time(sec,min,hou,day,week,mon,year);
			}						
		}																	
	}			
/************************   ++   ***********************/

	if(ircode==98)
	{
		ircode==0;
		if(clkbit==1)
		{	modify_ir=1;
			sec++;
			if(sec==60) sec=0;
			display_time();
			Locate_xy(7,0);			 //sec
			sentbyte(0x0d,0);
		}
		if(clkbit==2)
		{	modify_ir=1;
			min++;
			if(min==60) min=0;
			display_time();
			Locate_xy(4,0);			 //min
			sentbyte(0x0d,0);
		}
		if(clkbit==3)
		{	modify_ir=1;
			hou++;
			if(hou==24) hou=0;
			display_time();
			Locate_xy(1,0);			 //hou
			sentbyte(0x0d,0);
		}
		if(clkbit==4)
		{	modify_ir=1;
			day++;
			if(day==32) day=0;
			display_time();
			Locate_xy(9,1);			 //day
			sentbyte(0x0d,0);
		}
		if(clkbit==5)
		{	modify_ir=1;
			mon++;
			if(mon==13) mon=0;
			display_time();
			Locate_xy(6,1);			 //mon
			sentbyte(0x0d,0);
		}
		if(clkbit==6)
		{	modify_ir=1;
			year++;
			if(year==100) year=0;
			display_time();
			Locate_xy(3,1);			 //year
			sentbyte(0x0d,0);
		}
		if(clkbit==7)
		{	modify_ir=1;
			week++;
			if(week==7) week=0;
			display_time();
			Locate_xy(15,1);			 //week
			sentbyte(0x0d,0);
		}
	}

/************************   --   ***********************/

	if(ircode==168)
	{
		ircode==0;
		if(clkbit==1)
		{	modify_ir=1;
			sec--;
			if(sec<0) sec=59;
			display_time();
			Locate_xy(7,0);			 //sec
			sentbyte(0x0d,0);
		}
		if(clkbit==2)
		{	modify_ir=1;
			min--;
			if(min<0) min=59;
			display_time();
			Locate_xy(4,0);			 //min
			sentbyte(0x0d,0);
		}
		if(clkbit==3)
		{	modify_ir=1;
			hou--;
			if(hou<0) hou=23;
			display_time();
			Locate_xy(1,0);			 //hou
			sentbyte(0x0d,0);
		}
		if(clkbit==4)
		{	modify_ir=1;
			day--;
			if(day<0) day=31;
			display_time();
			Locate_xy(9,1);			 //day
			sentbyte(0x0d,0);
		}
		if(clkbit==5)
		{	modify_ir=1;
			mon--;
			if(mon<0) mon=12;
			display_time();
			Locate_xy(6,1);			 //mon
			sentbyte(0x0d,0);
		}
		if(clkbit==6)
		{	modify_ir=1;
			year--;
			if(year<0) year=99;
			display_time();
			Locate_xy(3,1);			 //year
			sentbyte(0x0d,0);
		}
		if(clkbit==7)
		{	modify_ir=1;
			week--;
			if(week<0) week=6;
			display_time();
			Locate_xy(15,1);			 //week
			sentbyte(0x0d,0);
		}
	}
}
